<?php

namespace july\julyadmin\builder\forms;

use july\julyadmin\builder\FormBase;
use \july\julyadmin\common\model\Config;

/**
 * 表单文件上传组件
 */
class File extends FormBase
{
    /**
     * 添加组件
     * @Author
     * @DateTime 2023-07-16T12:14:26+0800
     * @param    string                   $field 字段
     * @param    string                   $label 名称
     * @return this
     */
    public function __construct($field = '', $label = '')
    {
        $form                         = new \stdClass();
        $form->type                   = 'file';
        $form->field                  = $field;
        $form->label                  = $label;
        $form->placeholder            = $label;
        $form->help                   = '';
        $form->tips                   = ['tips' => '', 'direction' => 2, 'time' => 0, 'background' => '#000000'];
        $form->required               = false;
        $form->style                  = '';
        $form->multiple               = false;
        $form->isWriteData            = true;
        $form->selectServerFileShow   = true;
        $form->selectLocationFileShow = true;
        $form->ext                    = '';
        $form->showFileList           = true;
        $form->thumbWidth             = 100;
        $form->thumbHeight            = 100;

        //内容
        $form->value   = '';
        $form->default = '';
        $this->form    = $form;

        $this->js = '
            <!--上传插件-->
            <script type="text/javascript" src="/static/assets/admin/js/webuploader/webuploader.js"></script>
            <!--灯箱效果插件-->
            <script type="text/javascript" src="/static/assets/admin/js/magnific-popup/magnific-popup.min.js"></script>
        ';
        $this->css = '
            <!--上传插件css-->
            <link type="text/css" rel="stylesheet" href="/static/assets/admin/js/webuploader/webuploader.css">
            <!--灯箱效果插件css-->
            <link type="text/css" rel="stylesheet" href="/static/assets/admin/js/magnific-popup/magnific-popup.min.css">
        ';
        return $this;
    }

    /**
     * 是否显示文件列表
     * @Author   July
     * @DateTime 2023-11-09T21:25:32+0800
     * @param    boolean                  $show 是否显示文件列表
     * @return   this
     */
    public function showFileList($show = true)
    {
        $this->form->showFileList = $show;
        return $this;
    }

    /**
     * 设置允许上传格式，如jpg,png
     * @Author   July
     * @DateTime 2023-10-23T17:38:30+0800
     * @param    string                   $ext 文件格式jpg,png
     */
    public function setExt($ext = '')
    {
        $this->form->ext = $ext;
        return $this;
    }

    /**
     * 上传文件是否上传完成后直接写入数据库
     * @Author
     * @DateTime 2023-07-16T12:36:19+0800
     * @param    boolean                  $write 是否写入数据库,true,false
     * @return   this
     */
    public function isWriteData($write = true)
    {
        $this->form->isWriteData = $write;
        return $this;
    }

    /**
     * 是否显示选择服务器文件按钮
     * @Author   July
     * @DateTime 2023-10-13T22:10:53+0800
     * @param    boolean                  $show 是否显示
     * @return this
     */
    public function setSelectServerFile($show = true)
    {
        $this->form->selectServerFileShow = $show;
        return $this;
    }

    /**
     * 是否显示选择本地文件按钮
     * @Author   July
     * @DateTime 2023-10-13T22:11:41+0800
     * @param    boolean                  $show 是否显示
     * @return this
     */
    public function setSelectLocationFile($show = true)
    {
        $this->form->selectLocationFileShow = $show;
        return $this;
    }

    /**
     * 设置是否多选
     * @Author
     * @DateTime 2023-07-16T12:30:15+0800
     * @param    boolean                  $multiple 是否多选,true,false
     * @return   this
     */
    public function multiple($multiple = true)
    {
        $this->form->multiple = $multiple;
        return $this;
    }

    /**
     * 设置style
     * @Author
     * @DateTime 2023-07-16T12:19:05+0800
     * @param    string                   $style 样式，直接写css
     * @return   this
     */
    public function style($style = '')
    {
        $this->form->style = $style;
        return $this;
    }

    /**
     * 设置缩略图宽高
     * @Author   July
     * @DateTime 2023-11-17T20:30:41+0800
     * @param    integer                  $width  宽度，只能为数字
     * @param    integer                  $height 高度，只能为数字
     * @return   this
     */
    public function thumbSize($width = 165, $height = 110)
    {
        if (!is_numeric($width) || !is_numeric($height)) {
            throw new \Exception("宽度和高度只能为数字！");
        }
        if ($width <= 0 || $height <= 0) {
            throw new \Exception("宽度和高度不能小于等于0！");
        }
        $this->form->thumbWidth  = $width;
        $this->form->thumbHeight = $height;
        return $this;
    }

    /**
     * 渲染组件
     * @Author
     * @DateTime 2023-07-16T12:22:46+0800
     * @return   array
     */
    public function render($items_field = '')
    {
        if ($items_field) {
            $this->html        = '';
            $this->script      = '';
            $this->form->value = '';
        }
        $this->form->value = $this->form->default;
        if (isset($this->data[$this->form->field]) && $this->data[$this->form->field] !== "") {
            $this->form->value = $this->data[$this->form->field];
        }

        $app_map = config('app.app_map', []);
        $module  = 'admin';
        if ($app_map) {
            if ($key = array_search($module, $app_map)) {
                $module = $key;
            }
        }

        $required_html = $this->form->required && !$this->isView ? ' <font style="color:red;font-weight:bold;font-size:20px;vertical-align:-webkit-baseline-middle;">*</font>' : '';

        //处理tips
        $tips = '';
        if ($this->form->tips['tips']) {
            $tips = '<font class="form-tips-icon"><i class="mdi mdi-information-outline" tips="' . $this->form->tips['tips'] . '" direction="' . $this->form->tips['direction'] . '" time="' . $this->form->tips['time'] . '" background="' . $this->form->tips['background'] . '" onclick="showTips(this)"></i></font>';
        }

        $this->html .= <<< EOT

        <div class="row ps-0 pe-0 ms-0 me-0 mt-3 mb-3 col-md-{$this->colWidth}">
            <label class="col-sm-{$this->labelWidth} col-form-label pe-2 col-form-label-sm text-sm-end text-md-end text-lg-end text-xl-end">
                {$tips}{$this->form->label}
                {$required_html}
            </label>
EOT;
        $input_html = "";

        $multiple = $this->form->multiple ? 'true' : 'false';
        $values   = array_filter(explode(',', $this->form->value));

        $lis          = '';
        $imageSuffixs = ['png', 'jpg', 'jpeg', 'gif', 'bmp'];
        foreach ($values as $vk => $url) {
            $default_src = $url;
            $suffixs     = array_filter(explode('.', $url));
            if ($suffixs > 0) {
                $suffixs = strtolower($suffixs[count($suffixs) - 1]);
                if (!in_array($suffixs, $imageSuffixs)) {
                    $default_src = '/static/assets/admin/images/default-images/file.png';
                }
            }

            if (!$this->isView) {
                $delete = <<<EOT

                    <a class="btn btn-round btn-danger btn-remove-pic" data-id="{$url}">
                        <i class="mdi mdi-delete"></i>
                    </a>

EOT;
            } else {
                $delete = '';
            }

            $lis .= <<<EOT

            <li class="col-6 col-sm-3 col-md-2 list-files-item" id="{$url}">
                <figure style="min-width:{$this->form->thumbWidth}px !important;height:{$this->form->thumbHeight}px !important;">
                    <img src="{$default_src}"/>
                    <figcaption>
                        <a class="btn btn-round btn-primary btn-link-pic" href="{$url}">
                            <i class="mdi mdi-eye"></i>
                        </a>
                        {$delete}
                    </figcaption>
                </figure>
            </li>

EOT;
        }

        if (!$this->form->showFileList) {
            $lis = '';
        }
        $required = ($this->form->required ? ' required' : '');
        $buttons  = [];
        if ($this->form->selectLocationFileShow == true) {
            $buttons[] = '<div class="btn btn-primary ms-1" style="position:relative;" id="picker_' . $items_field . $this->form->field . $this->items_row_id_template_fun . '">上传' . '</div>';
        }
        if ($this->form->selectServerFileShow == true) {
            $buttons[] = '<div class="btn btn-primary ms-1" style="position:relative;" id="picker_server_' . $items_field . $this->form->field . $this->items_row_id_template_fun . '">选择' . '</div>';
        }
        $button = !$this->isView && !$this->readonly ? implode('', $buttons) : '';
        $size   = Config::config('FileUpload.fileMaxSize');
        if ($this->form->ext) {
            $ext = $this->form->ext;
        } else {
            $ext = Config::config('FileUpload.fileAllowFiles');
        }

        $fileVal        = Config::config('FileUpload.fileFieldName');
        $uploadUlr      = url('/' . $module . '/upload/fileUpload', ['isWriteData' => $this->form->isWriteData ? 1 : 0]);
        $uploadCheckUrl = url('/' . $module . '/upload/checkChunks');

        $readonly = $this->readonly ? 'readonly' : '';
        $type     = $this->isView ? 'hidden' : 'text';
        $input_html .= <<<EOT

                <div class="{$items_field}{$this->form->field}{$this->items_row_id_template_fun}-js-upload-files row gap-0">
                    <div class="ps-2.5">
                        <ul id="{$items_field}{$this->form->field}{$this->items_row_id_template_fun}_more_pics" class="list-inline row lyear-uploads-pic mt-2">
                            {$lis}
                        </ul>
                    </div>
EOT;
        if (!$this->isView) {
            $input_html .= <<<EOT
                    <div class="col col-sm-9">
                        <input type="{$type}" style="margin-bottom:10px;" class="form-control" id="{$items_field}{$this->form->field}{$this->items_row_id_template_fun}_input" name="{$this->items_row_prefix}{$this->form->field}" data-multiple="{$multiple}" data-size="{$size}" data-ext='{$ext}' value="{$this->form->value}" placeholder="{$this->form->placeholder}" {$required} {$readonly}/>
                    </div>
                    <div class="col-auto p-0">
                        {$button}
                    </div>


EOT;
        }

        $input_html .= <<<EOT

                </div>

EOT;

        //处理help
        if ($this->form->help) {
            $input_html .= <<<EOT

            <div class="form-help form-text">
                <i class="mdi mdi-information-outline"></i>
                <font>{$this->form->help}</font>
            </div>

EOT;
        }

        $this->html .= <<< EOT

            <div class="col-sm-{$this->inputWidth}">
                {$input_html}
            </div>
        </div>

EOT;

        $field        = md5($items_field . $this->form->field) . $this->items_row_id_template_fun;
        $uploadUrl    = url('/' . $module . '/Files/commonUploadForm');
        $showFileList = $this->form->showFileList ? 'true' : 'false';
        $this->script .= <<<EOT

            <script type="text/javascript">
                function initialize{$field}(){
                    var {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_chunks = [];

                    //这里要做判断，如果是要放到items组件的话这里必须要写，不然放在items中会出现样式错乱，无法点击
                    if('{$this->form->field}{$this->items_row_id_template_fun}'.indexOf('_____')>-1){
                        return false;
                    }
                    // 文件上传(单个文件，多个文件)
                    $('.{$items_field}{$this->form->field}{$this->items_row_id_template_fun}-js-upload-file,.{$items_field}{$this->form->field}{$this->items_row_id_template_fun}-js-upload-files').each(function() {
                        var input_file      = $(this).find('input'),
                            input_file_name = input_file.attr('name'),
                            multiple        = input_file.data('multiple'),  // 是否选择多个文件
                            ext             = input_file.data('ext'),       // 支持的文件后缀，示例以图片为例
                            size            = input_file.data('size');      // 支持最大的文件大小

                        var file_list = $('#{$items_field}{$this->form->field}{$this->items_row_id_template_fun}_more_pics');
                        var ratio = window.devicePixelRatio || 1;
                        var thumbWidth = {$this->form->thumbWidth} * ratio;
                        var thumbHeight = {$this->form->thumbHeight} * ratio;

                        var {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader = WebUploader.create({
                            auto: false,
                            duplicate: true,
                            resize: false,
                            swf: '/static/assets/admin/js/webuploader/Uploader.swf',
                            server: '{$uploadUlr}',
                            fileVal:'{$fileVal}',
                            chunked: true,//开启分片上传
                            chunkSize: 1024*1024*4,//每一分片的大小是4M
                            chunkRetry: 0,//如果遇到网络错误,重新上传次数
                            pick: {
                                id: '#picker_{$items_field}{$this->form->field}{$this->items_row_id_template_fun}',
                                multiple: multiple
                            },
                            fileSingleSizeLimit: size,
                            accept: {
                                title: '{$this->form->label}上传',
                                extensions: ext,
                                mimeTypes: '*'
                            }
                        });

                        //选择服务器文件
                        $("#picker_server_{$items_field}{$this->form->field}{$this->items_row_id_template_fun}").click(function(){
                            var uploadUrl = "{$uploadUrl}";
                            layer.open({
                                type: 2,
                                title: '{$this->form->label}上传',
                                shadeClose: false,
                                shade: 0.5,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['98%', '95%'],
                                content: uploadUrl + (uploadUrl.indexOf("?") > -1 ? "&" : "?") + "uploadMaxLength=" + (multiple?1000:1)+"&uploadCallback=uploadFileCallback_{$field}"
                            });
                        });

                        //文件加入队列之后
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('fileQueued', function (file) {
                            window.loading  = layer.load(2, { shade:  [0.2, '#000'] });
                            {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.md5File(file).then(function(md5) {
                                file.md5 = md5;
                                $.ajax({
                                    type:'POST',
                                    url:'{$uploadCheckUrl}',
                                    data:{md5: md5},
                                    dataType:'json',
                                    success:function(res) {
                                        layer.close(window.loading);
                                        if(res.code==1){
                                            switch (res.data.status) {
                                                //断点
                                                case 1:
                                                    //有断点.正在准备从断点处上传文件。
                                                    for (var i in res.data.chunks) {
                                                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_chunks.push(res.data.chunks[i]);
                                                    }
                                                break;
                                            }

                                            var li = $('<li class="col-6 col-sm-3 col-md-2 list-files-item" id="' + file.id + '">' +
                                                '  <figure style="min-width:{$this->form->thumbWidth}px !important;height:{$this->form->thumbHeight}px !important;">' +
                                                '    <img>' +
                                                '    <figcaption>' +
                                                '      <a class="btn btn-round btn-primary btn-link-pic" href="#!"><i class="mdi mdi-eye"></i></a>' +
                                                '      <a class="btn btn-round btn-danger btn-remove-pic" href="#!"><i class="mdi mdi-delete"></i></a>' +
                                                '    </figcaption>' +
                                                '  </figure>' +
                                                '</li>'),
                                            img = li.find('img');
                                            li.find('a.btn-link-pic').hide();
                                            if(res.data.fileinfo){
                                                //将当前文件设置为已上传，这样上传的时候就会跳过
                                                {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.skipFile(file,4);
                                                li.find('a.btn-link-pic').attr('href', res.data.fileinfo.url);
                                                li.find('.btn-remove-pic').attr('data-id', res.data.fileinfo.url);
                                                li.find('a.btn-link-pic').show();
                                                //如果文件已经上传过，返回文件地址
                                                var imageSuffixs = ["png", "jpg", "jpeg", "gif", "bmp"];
                                                var suffixs = res.data.fileinfo.url.split(".");
                                                var suffixs = suffixs[suffixs.length-1].toLowerCase();
                                                if(imageSuffixs.includes(suffixs)){
                                                    img.attr('src',res.data.fileinfo.url);
                                                }else{
                                                    img.attr('src','/static/assets/admin/images/default-images/file.png');
                                                }
                                                if (multiple) {
                                                    if({$showFileList}==true){
                                                        file_list.append(li);
                                                    }
                                                    if(input_file.val()){
                                                        input_file.val(input_file.val()+','+res.data.fileinfo.url);
                                                    }else{
                                                        input_file.val(res.data.fileinfo.url);
                                                    }
                                                } else {
                                                    if({$showFileList}==true){
                                                        file_list.html(li);
                                                    }
                                                    input_file.val(res.data.fileinfo.url);
                                                }

                                            }else{
                                                if (multiple) {
                                                    if({$showFileList}==true){
                                                        file_list.append(li);
                                                    }

                                                } else {
                                                    if({$showFileList}==true){
                                                        file_list.html(li);
                                                    }
                                                    input_file.val('');
                                                }
                                            }

                                            {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.makeThumb(file, function(error, src) {
                                                if (error) {
                                                    img.attr('src','/static/assets/admin/images/default-images/file.png');
                                                    return;
                                                }
                                                img.attr('src', src);
                                            }, thumbWidth, thumbHeight);
                                            if({$showFileList}==true){
                                                $('<div class="progress progress-sm"><div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div></div>').appendTo(li);
                                            }

                                            //上传文件
                                            if(!res.data.fileinfo){
                                                {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.upload();
                                            }
                                            setTimeout(function(){
                                                formValidate();
                                                $(window).resize();
                                            },500);
                                        }else{
                                            layer.msg(res.hasOwnProperty('msg') && res.msg?res.msg:'操作失败！',{
                                                icon:5,
                                                time:2000,
                                                shade:[0.6,'#000',false]
                                            });
                                        }
                                        setTimeout(function(){
                                            $(window).resize();
                                        },500);
                                    },
                                    error:function(res){
                                        $(window).resize();
                                        layer.close(window.loading);
                                        layer.msg(JSON.stringify(res),{
                                            icon:5,
                                            time:2000,
                                            shade:[0.6,'#000',false]
                                        });
                                    }
                                });
                            });
                            setTimeout(function(){
                                formValidate();
                                $(window).resize();
                            },500);
                        });

                        //发送前检查分块,并附加MD5数据
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('uploadBeforeSend', function(block,data) {
                            var file = block.file;
                            var deferred = WebUploader.Deferred();
                            data.md5 = file.md5;
                            if ($.inArray(block.chunk.toString(), {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_chunks) >= 0) {
                                // console.log("已有分片.正在跳过分片"+block.chunk.toString());
                                //跳过该分片
                                deferred.reject();
                            }else{
                                //没有分片，继续上传
                                // console.log("没有分片.继续上传分片"+block.chunk.toString());
                                //继续上传该分片
                                deferred.resolve();
                            }
                            $(window).resize();
                            return deferred.promise();
                        });

                        setTimeout(function(){
                            $(window).resize();
                        },500);

                        //上传中
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('uploadProgress', function(file, percentage) {
                            var percent = $('#' + file.id).find('.progress-bar');
                            percent.css('width', percentage * 100 + '%');
                        });

                        //上传成功
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('uploadSuccess', function(file, res) {
                            if (res.code == 1) {
                                if(res.data.status==1){
                                    var li = $('#' + file.id);
                                    if (multiple) {
                                        if(input_file.val()){
                                            input_file.val(input_file.val()+','+res.data.urls[0]);
                                        }else{
                                            input_file.val(res.data.urls[0]);
                                        }
                                    } else {
                                        input_file.val(res.data.urls[0]);
                                    }
                                    $('<div class="' + res.class + ' success"></div>').text(res.info).appendTo(li);

                                    li.find('a.btn-link-pic').attr('href', res.data.urls[0]);
                                    li.find('a.btn-link-pic').show();
                                    li.find('.btn-remove-pic').attr('data-id', res.data.urls[0]);
                                }
                                $(window).resize();
                                formValidate();
                            }
                        });
                        //上传错误
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('uploadError', function(file) {
                            var li = $('#' + file.id);
                            $('<div class="bg-danger error">上传失败</div>').appendTo(li);
                            $(window).resize();
                        });

                        //错误
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('error', function(type) {
                            switch (type) {
                                case 'Q_TYPE_DENIED':
                                layer.msg('文件类型不正确，只允许上传后缀名为：' + ext + '，请重新上传！',{
                                    icon:5,
                                    time:2000,
                                    shade:[0.6,'#000',false]
                                });
                                break;
                                case 'F_EXCEED_SIZE':
                                layer.msg('文件不得超过' + (size / 1024) + 'kb，请重新上传！',{
                                    icon:5,
                                    time:2000,
                                    shade:[0.6,'#000',false]
                                });
                                break;
                            }
                            $(window).resize();
                        });
                        //上传完成
                        {$items_field}{$this->form->field}{$this->items_row_id_template_fun}_uploader.on('uploadComplete', function(file) {
                            setTimeout(function() {
                                $('#' + file.id).find('.progress').remove();
                                $(window).resize();
                            }, 500);
                        });
                        //删除操作
                        file_list.delegate('.btn-remove-pic', 'click', function() {
                            if (multiple) {
                                var id = $(this).data('id'),
                                ids = input_file.val().split(',');
                                if (id) {
                                    for (var i = 0; i < ids.length; i++) {
                                        if (ids[i] == id) {
                                            ids.splice(i, 1);
                                            break;
                                        }
                                    }
                                    input_file.val(ids.join(','));
                                }
                            } else {
                                input_file.val('');
                            }
                            $(this).closest('.list-files-item').remove();
                            $(window).resize();
                        });

                        //接入图片查看插件
                        $(this).magnificPopup({
                            delegate: 'a.btn-link-pic',
                            type: 'iframe',
                            gallery: {
                                enabled: true
                            }
                        });
                    });
                }

                //服务器文件选择回调
                function uploadFileCallback_{$field}(urls){
                    urls.map(item=>{
                        var input_file      = $('#{$items_field}{$this->form->field}{$this->items_row_id_template_fun}_input'),
                            multiple        = input_file.data('multiple');  // 是否选择多个文件

                        var file_list = $('#{$items_field}{$this->form->field}{$this->items_row_id_template_fun}_more_pics');
                        var li = $('<li class="col-6 col-sm-3 col-md-2 list-files-item" id="' + item.id + '">' +
                            '  <figure style="min-width:{$this->form->thumbWidth}px !important;height:{$this->form->thumbHeight}px !important;">' +
                            '    <img>' +
                            '    <figcaption>' +
                            '      <a class="btn btn-round btn-primary btn-link-pic" href="#!"><i class="mdi mdi-eye"></i></a>' +
                            '      <a class="btn btn-round btn-danger btn-remove-pic" href="#!"><i class="mdi mdi-delete"></i></a>' +
                            '    </figcaption>' +
                            '  </figure>' +
                            '</li>'),
                        img = li.find('img');
                        li.find('a.btn-link-pic').hide();
                        li.find('a.btn-link-pic').attr('href', item.url);
                        li.find('.btn-remove-pic').attr('data-id', item.url);
                        li.find('a.btn-link-pic').show();
                        //如果文件已经上传过，返回文件地址
                        var imageSuffixs = ["png", "jpg", "jpeg", "gif", "bmp"];
                        var suffixs = item.url.split(".");
                        var suffixs = suffixs[suffixs.length-1].toLowerCase();
                        if(imageSuffixs.includes(suffixs)){
                            img.attr('src',item.url);
                        }else{
                            img.attr('src','/static/assets/admin/images/default-images/file.png');
                        }
                        if (multiple) {
                            if({$showFileList}==true){
                                file_list.append(li);
                            }
                            if(input_file.val()){
                                input_file.val(input_file.val()+','+item.url);
                            }else{
                                input_file.val(item.url);
                            }
                        } else {
                            if({$showFileList}==true){
                                file_list.html(li);
                            }
                            input_file.val(item.url);
                        }
                    });

                    //接入图片查看插件
                    $(this).magnificPopup({
                        delegate: 'a.btn-link-pic',
                        type: 'iframe',
                        gallery: {
                            enabled: true
                        }
                    });
                    formValidate();
                    setTimeout(function(){
                        $(window).resize();
                    },1000);
                }

                initialize{$field}();
                </script>

EOT;
        $result = ['html' => $this->html, 'script' => $this->script];
        return $result;
    }
}
